//  https://www.luogu.com.cn/problem/P1706

#include<iostream>
#include<vector>
using namespace std;

int n;
vector<int> path;
bool st[10];


void dfs()
{
    if (path.size() == n)
    {
        for (auto x : path)
            printf("%5d", x);
        cout << endl;
        return;
    }
    for (int i = 1;i <= n;i++)
    {
        if (st[i]) continue;
        path.push_back(i);
        st[i] = true;
        dfs();
        path.pop_back();
        st[i] = false;
    }
}
int main()
{
    cin >> n;
    dfs();
    return 0;
}